import time
from flask import current_app
from extensions import celery, db, stock_redis
from ..models import StockGood
from celery_redis_sentinel import register

register()

__all__ = ['stock_regist_task']


@celery.context_task(bind=True, default_retry_relay=15, max_retires=5)
def stock_regist_task(self, req_data):
    """
        销售库存登记任务
        :param req_data:

            skus = [
                {
                    "sku_id": '401190024',
                    "num": 1,
                    'source_order': '16081214474205012871'
                },
                {
                    "sku_id": '401190024',
                    "num": 1,
                    'source_order': '16081214474205012871'
                }
            ]
            payload = {
                "order_id": 'D1608230000121',
                "source_ids": ['16081214474205012871', '16081214474205012872'],
                "business_type": 25,
                "data": skus,
                "user_id": "OFC",
                "sys_id": "OFC"
            }

    """

    try:
        print("ttttttttttttttttttttttttttt")
        return {'code': 0, 'msg': 'successed', 'data': []}, 200
    except Exception as ex:
        current_app.logger.error(ex, exc_info=1)
        raise self.retry(exc=ex, countdown=10)